function showEditor(id) {
    var content = $("#content_" + id);
    var editorArea = $("#editorArea_" + id);
    var editor = $("#editor_" + id);
    editor.val(content.text());

    editorArea.show();

    $("#switcher_" + id).attr("src", "themes/icons/ok.png").attr("title", "保存");
    content.hide();
}

function hideEdit(id, withSubmit) {
    var content = $("#content_" + id);
    var editorArea = $("#editorArea_" + id);
    var editor = $("#editor_" + id);
    editorArea.hide();
    var text = editor.val();
    
    var old = content.text();
    
    //...
    //显示原内容。。
    if (validationInput(editor) == false) { 
    	 content.text(old);
    } else 
    {
    	 
    	if (withSubmit == true) {
            if (old!= text) {
                submitChanged(id, text);
            } 
    	} 
    	editor.val(text);
    }
    $("#switcher_" + id).attr("src", "themes/icons/edit.png").attr("title", "进行编辑");
    content.show();
    
}

function switchSave(id, withSubmit) {
    var ___id = "#sender_" + id;
    var sender = $(___id);
    var stateCode = sender.attr("state");
    if (stateCode == 0 || stateCode == undefined) {
        // 进行保存 。 
        $(sender).attr("state", 1);
        showEditor(id);

    }
    if (stateCode == 1) { 
        $(sender).attr("state", 0); 
        hideEdit(id, withSubmit);
    }
}

function cancelSave(id, withSubmit) {
    switchSave(id, false);
}


function editorEventsRegiste() {
    $(".textPanel").live("click", function () {
        var __id = $(this).attr("oid");
        $("#sender_" + __id).click();
        $("#editor_" + __id).focus();
    });
    $(".textBox").live("blur", function () {
        var __id = $(this).attr("oid");
        $("#sender_" + __id).click();
    });
    $(".textBox").live("keydown", function (e) {
    	if (e.keyCode == 13) {
    		$("#sender_" + $(this).attr("oid")).click(); //处理事件 
    	}
 	});

}